package com.rgs.gateway.common.enums;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * @ProjectName: meix-api-gateway
 * @Package: com.meix.api.common.core.enums
 * @ClassName: SignTypeEnum
 * @Author: cao
 * @Description:
 * @Date: 2023/11/16 15:34
 * @Version: 1.0
 */
@Getter
@AllArgsConstructor
public enum SignTypeEnum {

    COMMON(1, "公共验签方式"),
    DATACENTER(2, "数据中台验签方式"),
    SIMUAI(3, "易私慕AI验签方式"),
    SIMU(4, "易私慕验签方式");

    private Integer codeValue;

    private String codeText;

    public static SignTypeEnum getInstance(Integer type) {
        SignTypeEnum[] values = SignTypeEnum.values();
        for (SignTypeEnum value : values) {
            if (type.intValue() == value.getCodeValue().intValue()) {
                return value;
            }
        }
        return COMMON;
    }

    public static SignTypeEnum getInstance(String codeText) {
        SignTypeEnum[] values = SignTypeEnum.values();
        for (SignTypeEnum value : values) {
            if (Objects.equals(codeText, value.getCodeText())) {
                return value;
            }
        }
        return COMMON;
    }

    public static String getCodeText(Integer codeValue) {
        SignTypeEnum[] values = values();
        for (SignTypeEnum value : values) {
            if (value.getCodeValue().equals(codeValue)) {
                return value.getCodeText();
            }
        }
        return COMMON.codeText;
    }

    public static Integer parse(String codeText) {
        SignTypeEnum[] values = values();
        for (SignTypeEnum value : values) {
            if (value.getCodeText().equals(StrUtil.trim(codeText))) {
                return value.getCodeValue();
            }
        }
        return COMMON.codeValue;
    }
}
